package com.example.elasticsearch.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.AccessLevel;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
@Document(indexName = "company_2")
@Setting(settingPath = "/template/comma_analyzer_setting.json")
public class CompanyPo implements Serializable {
    static final long serialVersionUID = -7852649991589478518L;

    /**
     * 企业id
     */
    @Id
    Integer id;

    /**
     * 企业名称
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    String companyName;

    @Field(type = FieldType.Keyword)
    String companyNameKeyword;

    @Field(type = FieldType.Keyword)
    String companyOrgCode;

    @Field(type = FieldType.Integer)
    Integer provinceId;

    @Field(type = FieldType.Integer)
    Integer cityId;

    @Field(type = FieldType.Integer)
    Integer disId;

    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    String address;

    /**
     * 数据用例,多个以逗号分割
     * 1,2,3,4
     */
    @Field(type = FieldType.Text, analyzer = "comma", searchAnalyzer = "comma")
    String companyTypes;

    @Field(type = FieldType.Keyword)
    String registereDcapital;

    @Field(type = FieldType.Float)
    BigDecimal registereDcapitalMoney;

    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    LocalDateTime createTime;

    @Field(type = FieldType.Nested, name = "attributerelations")
    List<CompanyAttributeRelationPo> attributerelations;

    @GeoPointField
    CoordinatePo coordinatePo;
}
